package com.cheboohui.iqs.deal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.alibaba.fastjson.JSONObject;
import com.cheboohui.iqs.config.Config;
import com.cheboohui.iqs.config.PrivateTool;
import com.cheboohui.iqs.controller.BaseController;
import com.cheboohui.iqs.taiping.direct.e.E03Request;
import com.cheboohui.iqs.taiping.direct.e.E07Request;

/**
 * 自定义接口处理
 * 
 * @author xielonghai
 *
 */
public class CustomizeDeal {
	/**
	 * logger:日志工具.
	 */
	private static Log log = LogFactory.getLog(CustomizeDeal.class);

	/**
	 * 自定义接口处理
	 * 
	 * @param request
	 * @param response
	 */
	public static void customize(HttpServletRequest request, HttpServletResponse response) {
		log.info("进入" + Config.value + ",自定义处理接口....");
		try {
			JSONObject param = PrivateTool.paramtenToJson(request.getParameterMap());
			if (null == param)
				BaseController.setResponseText(response, "请求参数获取转化异常");
			log.info(Config.value + ",自定义处理接口请求参数:" + param);

			BaseController.setResponseText(response, typeDeal(param));
			return ;
		} catch (Exception e) {
			log.error(Config.value + ",自定义处理接口实现异常:" + e);
			BaseController.setResponseText(response, "自定义处理接口实现异常:" + e.getMessage());
		}
	}
	
	/**接口处理
	 * @param param
	 * @return
	 */
	private static String typeDeal(JSONObject param){
		switch (param.getString("type")) {
		case "e03":
			return JSONObject.toJSONString(
					E03Request.requestE03("", "", param.getString("licenseNo"), param.getString("num")));
		case "e07":
			return JSONObject.toJSONString(
					E07Request.requestE07("", param.getString("orderNo"), param.getString("idCard")));
		case "set":
			return "暂时该接口未启用-set";
		default:
			return "暂时该接口未启用";
		}
	}
}
